JS - element properties - tagName

revision:


returns the tag name of an element.

top

It returns the tag name in UPPERCASE.
The property is read-only.

Syntax:

element.tagName : string - returns the tag name of the element (in uppercase).

property value:

none :

example

The tag name of the "prop57" element is:

Click on any element in this div to see which element triggered the onclick event.

This is span element.

code:
                <div>
                    <p>The tag name of the "prop" element is: <span id="prop57"></span></p> 
                    <div onclick="fistFunction(event)">
                        <p>Click on any element in this div to see which element triggered the onclick event.</p>
                        <button>This is a button</button>
                        <p><span>This is span element.</span></p>
                        <p id="prop"></p>
                    </div>
                </div>
                <script>
                    let name = document.getElementById("prop").tagName;
                    document.getElementById("prop").innerHTML = name;
        
                    function firstFunction(event) { 
                        const element = event.target;
                        document.getElementById("prop").innerHTML = "Triggered by " + element.tagName;
                    }
                </script>